﻿using System;
using System.Net;
using System.Windows.Threading;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace DX_DailyUtil_1._0._1.ks.ui.effect
{
    public class Slide
    {

        private Timer mTimer = null;
        private Grid mOutGrid;
        private Grid mPanel;
        private Dispatcher mDispatcher;

        public Slide(Grid aOutGrid, Grid aPanel, Dispatcher aDispatcher)
        {
            this.mOutGrid = aOutGrid;
            this.mPanel = aPanel;
            this.mDispatcher = aDispatcher;
        }

        public void runSelf()
        {
            double _start = this.mOutGrid.ColumnDefinitions[0].Width.Value;
            mTimer = new Timer(new TimerCallback(oTimerCallback), _start, 100, 5);
        }

        private void oTimerCallback(object o)
        {
            this.mDispatcher.BeginInvoke(
              delegate()
              {
                  double _start = (double)o;
                  show_calc(_start);
              });
        }

        private void show_calc(double aStartWidth)
        {
            if (aStartWidth < 40)
            {
                if (this.mOutGrid.ColumnDefinitions[0].Width.Value >= 73d)
                {
                    this.mPanel.Visibility = Visibility.Visible;
                    this.mPanel.Opacity = 1.0d;
                    this.mOutGrid.ColumnDefinitions[0].Width = new GridLength(73, GridUnitType.Star);
                    this.mTimer.Dispose();
                }
                else
                {
                    this.mPanel.Visibility = Visibility.Visible;
                    this.mPanel.Opacity += 0.05d;
                    double _temp = this.mOutGrid.ColumnDefinitions[0].Width.Value;
                    this.mOutGrid.ColumnDefinitions[0].Width = new GridLength(_temp + 3, GridUnitType.Star);
                }
            }
            else
            {
                if (this.mOutGrid.ColumnDefinitions[0].Width.Value <= 13d)
                {
                    this.mPanel.Visibility = Visibility.Collapsed;
                    this.mPanel.Opacity = 0.0d;
                    this.mOutGrid.ColumnDefinitions[0].Width = new GridLength(13, GridUnitType.Star);
                    this.mTimer.Dispose();
                }
                else
                {
                    this.mPanel.Opacity -= 0.05d;
                    double _temp = this.mOutGrid.ColumnDefinitions[0].Width.Value;
                    this.mOutGrid.ColumnDefinitions[0].Width = new GridLength(_temp - 3, GridUnitType.Star);
                }
            }
        }
    }
}
